// stylelint-disable max-line-length

@use '@material/theme/theme-color' as mdc-theme-color;
@use '@material/theme/theme' as mdc-theme;
@use '@material/list' as mdc-list;
@use '@material/typography' as mdc-typography;
@use '@material/ripple' as mdc-ripple;
@use '../../mdc-helpers/mdc-helpers';
@use '../../../material/core/theming/theming';

@mixin option-color($config-or-theme) {
  $config: theming.get-color-config($config-or-theme);

  @include mdc-helpers.mat-using-mdc-theme($config) {
    .mat-mdc-option {
      // Since this will usually be rendered in an overlay,
      // we have explicitly set the default color.
      @include mdc-theme.prop(color, text-primary-on-background);
      @include mdc-list.deprecated-item-disabled-text-color(
        mdc-list.$deprecated-text-disabled-color, $query: mdc-helpers.$mat-theme-styles-query);

      &:hover:not(.mdc-deprecated-list-item--disabled),
      &:focus:not(.mdc-deprecated-list-item--disabled),
      &.mat-mdc-option-active,

      // In multiple mode there is a checkbox to show that the option is selected.
      &.mdc-deprecated-list-item--selected:not(.mat-mdc-option-multiple):not(.mdc-deprecated-list-item--disabled) {
        $color: mdc-theme-color.$on-surface;
        background: rgba($color, mdc-ripple.states-opacity($color, hover));
      }
    }

    .mat-primary {
      .mat-mdc-option.mdc-deprecated-list-item--selected:not(.mdc-deprecated-list-item--disabled) {
        @include mdc-list.deprecated-item-primary-text-ink-color(
                primary, $query: mdc-helpers.$mat-theme-styles-query);
      }
    }

    .mat-accent {
      .mat-mdc-option.mdc-deprecated-list-item--selected:not(.mdc-deprecated-list-item--disabled) {
        @include mdc-list.deprecated-item-primary-text-ink-color(
                secondary, $query: mdc-helpers.$mat-theme-styles-query);
      }
    }

    .mat-warn {
      .mat-mdc-option.mdc-deprecated-list-item--selected:not(.mdc-deprecated-list-item--disabled) {
        @include mdc-list.deprecated-item-primary-text-ink-color(
                error, $query: mdc-helpers.$mat-theme-styles-query);
      }
    }
  }
}

@mixin option-typography($config-or-theme) {
  $config: theming.get-typography-config($config-or-theme);

  @include mdc-helpers.mat-using-mdc-typography($config) {
    // MDC uses the `subtitle1` level for list items, but the spec shows `body1` as the correct
    // level. Class is repeated for increased specificity.
    .mat-mdc-option {
      @include mdc-typography.typography(body1, $query: mdc-helpers.$mat-typography-styles-query);
    }
  }
}

@mixin option-density($config-or-theme) {
  $density-scale: theming.get-density-config($config-or-theme);
}

@mixin option-theme($theme-or-color-config) {
  $theme: theming.private-legacy-get-theme($theme-or-color-config);
  @include theming.private-check-duplicate-theme-styles($theme, 'mat-mdc-option') {
    $color: theming.get-color-config($theme);
    $density: theming.get-density-config($theme);
    $typography: theming.get-typography-config($theme);

    @if $color != null {
      @include option-color($color);
    }
    @if $density != null {
      @include option-density($density);
    }
    @if $typography != null {
      @include option-typography($typography);
    }
  }
}
